﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ThangNM_LIB.FUNC;
using EntityObject;
using ThangNM_LIB.DB;
using ThangNM_Client.SharedLibraries;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessObject
{
    public class PHDDAO : SQLiteDataProvider
    {
        public override Boolean bWriteLog { get { return false; } set { } }
        public override String sConnectionStrings { get { return ConstEx.connectionStrings.connSqLite_FB; } set { } }

        public PHDDAO(Boolean _bWriteLog = true, String _sConnectionStrings = ConstEx.connectionStrings.connSqLite_FB)
        {
            this.bWriteLog = _bWriteLog;
            this.sConnectionStrings = _sConnectionStrings;
        }

        public Boolean Insert_Update_Delete(PHDEO objInput, Int16 _Insert_Update_Delete)
        {
            String sQuery = String.Format(QuerySQLiteLIB.PHD.InsertItem, objInput.PK_iVID, objInput.sTitle, objInput.sDescription, objInput.sKeyword, objInput.sInfoEx, objInput.sUrl, objInput.sImagePoster, objInput.sImageSmall, objInput.sImageMedium, objInput.sImageLarge,
                    objInput.sVideo240p, objInput.sVideo480p, objInput.sVideo720p, objInput.sVideo1080p, objInput.iVideoServerId, objInput.PK_iVID);
            sQuery = NullEx.getNullValueSQLite(sQuery);
            SqlCommand cmd = new SqlCommand(sQuery);
            cmd.CommandType = CommandType.Text;
            return ExecuteNonQuery(cmd);
        }

        public Boolean Update_Info_Video(PHDEO objInput)
        {
            String sQuery = String.Format(QuerySQLiteLIB.PHD.Update_Info_Video, objInput.sVideo240p, objInput.sVideo480p, objInput.sVideo720p, objInput.sVideo1080p, objInput.PK_iVID);
            sQuery = NullEx.getNullValueSQLite(sQuery);
            SqlCommand cmd = new SqlCommand(sQuery);
            cmd.CommandType = CommandType.Text;
            return ExecuteNonQuery(cmd);
        }

        public PHDEO SelectItem(Int64 PK_iVID)
        {
            String sQuery = String.Format(QuerySQLiteLIB.PHD.SelectItem, PK_iVID);
            sQuery = NullEx.getNullValueSQLite(sQuery);
            SqlCommand cmd = new SqlCommand(sQuery);
            cmd.CommandType = CommandType.Text;
            return PHDDO(GetDataTable(cmd));
        }

        public DataSet SelectBy_Page_Default(String Order, Int32 PageSize, Int32 PageNumber)
        {
            String sQuery = String.Format(QuerySQLiteLIB.PHD.SelectBy_Page_Default, Order, PageSize, PageNumber);
            sQuery = NullEx.getNullValueSQLite(sQuery);
            SqlCommand cmd = new SqlCommand(sQuery);
            cmd.CommandType = CommandType.Text;
            return GetDataSet(cmd);
        }

        public DataTable SelectBy_Page_Search(String Query, String Order, Int32 PageSize, Int32 PageNumber)
        {
            String sQuery = String.Format(QuerySQLiteLIB.PHD.SelectBy_Page_Search, Query, Query, Order, PageSize, PageNumber);
            sQuery = NullEx.getNullValueSQLite(sQuery);
            SqlCommand cmd = new SqlCommand(sQuery);
            cmd.CommandType = CommandType.Text;
            return GetDataTable(cmd);
        }

        public PHDEO PHDDO(DataTable dtInput)
        {
            List<PHDEO> lstTemp = new List<PHDEO>();
            lstTemp = (List<PHDEO>)ConvertEx.ConvertDataTableToListObject<PHDEO>(dtInput, lstTemp.GetType());
            if (CommonsCheck.ListObject_OK(lstTemp))
                return lstTemp[0];
            else
                return null;
        }
    }
}